<?php
include dirname(__FILE__)."/../utils/utils.php";
session_start();
if(!Utils::isLoggedIn()){
	die('You are not allowed to access this page.');
}
$objectType = isset($_GET['objectType'])?$_GET['objectType']:'';
if ($objectType == "team") {
	$teamId = isset($_GET['teamId'])?$_GET['teamId']:"-1";
	include "dbmanager.php";
	$pDatabase = Database::getInstance();
	
	$sql="DELETE FROM image WHERE teamId = ".$teamId;
	$result = $pDatabase->query($sql);
	if (!$result) {
		die('Error: ' . mysql_error());
	}
	
	$sql="DELETE FROM team WHERE id = ".$teamId;
	$result = $pDatabase->query($sql);
	if (!$result) {
		die('Error: ' . mysql_error());
	} else {
		header("Location: ../../index.php?site=admin");
	}
} else if ($objectType == "image") {
	$imageId = isset($_GET['imageId'])?$_GET['imageId']:"-1";
	$teamId = isset($_GET['teamId'])?$_GET['teamId']:"-1";
	include "dbmanager.php";
	$pDatabase = Database::getInstance();
	
	$sql="DELETE FROM image WHERE id = ".$imageId;
	$result = $pDatabase->query($sql);
	if (!$result) {
		die('Error: ' . mysql_error());
	} else {
		header("Location: ../../index.php?site=admin&submenu=editimage&id=".$teamId);
	}
}
?>